﻿#include "myhead.h"

void assign_capy(const char *path) //指定文件打印
{
	char * p = NULL;
    //打开目录
    DIR *dir = opendir(path);
	char buf[256] = {};
    if(!dir){
        perror("opendir");
        return;
    }

    //读取目录
    struct dirent *dp = NULL;
	
    while(dp = readdir(dir)){
        //.和..要忽略
        if(strcmp(dp->d_name,".")==0||strcmp(dp->d_name,"..")==0)
            continue;

        //目录
        if(dp->d_type==DT_DIR){
            sprintf(buf,"%s/%s",path,dp->d_name);
            print_dir(buf);
        }
		else{
			
			if(strstr(dp->d_name,".txt")!=NULL)
			printf("文件 %s\n",dp->d_name);
        }
    }

    //关闭目录
    closedir(dir);
}

int main(int argc,char *argv[])
{
    if(argc!=2){
        printf("%s dirpath\n",argv[0]);
        return -1;
    }

    print_dir(argv[1]);

    return 0;
}